<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>

	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : '{{ urlfor "ProductsController.DataGrid"}}'
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var params = checkQueryTableData(aoData)
			$('#search_key').val() ? params.filter = $('#search_key').val() : ''
			params.Status = 1;
			params.ClassType = 60;
			
			$.post(sSource, JSON.stringify(params),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
			{"data" : "Id", "bSortable": false}
			,{"data" : "Identifier", "bSortable": false}
			,{"data" : "FullName", "bSortable": false}
            ,{"data":"Class",render:function(data, type, full, meta) {
                    return full.ClassName;
            }}
			,{
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"10%",
				"render": function ( data, type, full, meta ) { 
					btns = '<a href="javascript:;" class="am-btn am-btn-success am-btn-xs" onclick="return selectProducts('+ meta.row +');">选择</a>';
					return btns;  
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	
	$("#searchsubmit").bind("submit", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
		return false;
	});
	$('#search_key').keyup(function(){
		if($(this).val() == '') {
			return false;	
		}
		$("#dataTables").dataTable().fnDraw(false);
		return false;
	});
	
	$('#dataTables tbody').on('dblclick','tr', function () {
		var i = tables.row(this).index();
		selectProducts(i);
	});
	
	function selectProducts(d) {
		var data = tables.row(d).data();
		data.isProduct = 1;
		parent.receiveFormData(data);
		//parent.layer.closeAll('iframe');
		return false;
	}
	
	
	
</script>